package listener;

import gui.ChessGUI;
import gui.PieceGUI;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Arc;
import javafx.scene.shape.Circle;
import logic.ChessGame;
import logic.Move;
import logic.Piece;

public class PieceHandlerMouseDragging implements EventHandler<MouseEvent> {

	private PieceGUI pieceGUI;
	private ChessGame chessGame;
	private ChessGUI chessGUI;

	public PieceHandlerMouseDragging(PieceGUI pieceGUI, ChessGUI chessGUI) {
		this.pieceGUI = pieceGUI;
		this.chessGUI = chessGUI;
		this.chessGame = chessGUI.getChessGame();

	}

	@Override
	public void handle(MouseEvent event) {
		pieceGUI.setCursor(Cursor.HAND);
		chessGUI.showMarkPoints();
		// for (int i = Piece.COLUMN_A; i <= Piece.COLUMN_I; i++) {
		// for (int j = Piece.ROW_1; j <= Piece.ROW_9; j++) {
		//
		// int sourceRow = pieceGUI.getY();
		// int sourceCol = pieceGUI.getX();
		// if (chessGame.getMoveValidator().isMoveValid(
		// new Move(sourceRow, sourceCol, j, i), false)) {
		// javafx.scene.shape.Circle arc = new Circle((30 + i * 50),
		// (30 + j * 50), 10);
		// chessGUI.addMarkPoint(arc);
		// }
		// }
		// }

		double x = event.getSceneX() - 230;
		double y = event.getSceneY() - 30;

		// System.out.println(x + "/" + y);
		if ((x) % 50 < 20 && (y) % 50 < 20) {
			pieceGUI.setX((int) x / 50);
			pieceGUI.setY((int) y / 50);
			// this.chessGUI.resetPiecesByCoor();
		}
	}
}
